package gold.digger;

import java.util.Stack;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC232 {

    /*
    * @param 此题目直接用别人代码，自己只理解思想
    * @return:
    */
    class MyQueue {

        private Stack<Integer> s1, s2;

        /**
         * Initialize your data structure here.
         */
        public MyQueue() {
            s1 = new Stack<>();
            s2 = new Stack<>();
        }

        /**
         * 添加元素到队尾
         */
        public void push(int x) {
            s1.push(x);
        }

        /**
         * 返回队头元素
         */
        public int peek() {
            if (s2.isEmpty())
                // 把 s1 元素压入 s2
                while (!s1.isEmpty())
                    s2.push(s1.pop());
            return s2.peek();
        }

        /**
         * 删除队头的元素并返回
         */
        public int pop() {
            // 先调用 peek 保证 s2 非空
            peek();
            return s2.pop();
        }

        /**
         * 判断队列是否为空
         */
        public boolean empty() {
            return s1.isEmpty() && s2.isEmpty();
        }
    }


    public static void main(String[] args) {
        LC232 an = new LC232();

        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
    }
}
